package xxy.com.customview.modle;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by Administrator on 2018/1/11.
 */

public class UserPacelable implements Parcelable{
    public int age = 25;
    public String name = "徐晓阳";
    public String phone = "13564315424";

    public UserPacelable(int age, String name, String phone) {
        this.age = age;
        this.name = name;
        this.phone = phone;
    }


    //实现Parcelable需要的方法
    protected UserPacelable(Parcel in) {
        age = in.readInt();
        name = in.readString();
        phone = in.readString();
    }

    //实现Parcelable需要的方法
    public static final Creator<UserPacelable> CREATOR = new Creator<UserPacelable>() {
        @Override
        public UserPacelable createFromParcel(Parcel in) {
            return new UserPacelable(in);
        }

        @Override
        public UserPacelable[] newArray(int size) {
            return new UserPacelable[size];
        }
    };

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    //实现Parcelable需要的方法
    @Override
    public int describeContents() {   //一般都是0
        return 0;
    }

    //实现Parcelable需要的方法
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(age);
        dest.writeString(name);
        dest.writeString(phone);
    }
}
